import logging

from config import URL


class RechargeApi(object):
    def __init__(self, session):
        self.session = session

    def get_recharge_verify_code(self, r):
        url = URL + "/common/public/verifycode/{}".format(r)
        response = self.session.get(url=url)
        logging.info("获取充值验证码接口返回的响应状态码:{}".format(response.status_code))
        return response

    def recharge(self, amount_v, valicode_v, paymentType_v='chinapnrTrust', formStr_v='reForm'):
        url = URL + "/trust/trust/recharge"
        form_data = {'paymentType': paymentType_v,
                     'amount': amount_v,
                     'formStr': formStr_v,
                     'valicode': valicode_v}
        response = self.session.post(url=url, data=form_data)
        logging.info("充值接口返回的响应数据:{}".format(response.json()))
        return response

    def third_recharge(self, url, form_data):
        response = self.session.post(url=url, data=form_data)
        logging.info("第三方充值接口返回的响应数据:{}".format(response.text))
        return response
